﻿using Microsoft.Phone.Controls;
using CDFWPUG.Helpers;
using GalaSoft.MvvmLight.Messaging;
using System;
using CDFWPUG.ViewModel;

namespace CDFWPUG
{
    /// <summary>
    /// Description for panMain.
    /// </summary>
    public partial class panMain : PhoneApplicationPage
    {
        /// <summary>
        /// Initializes a new instance of the panMain class.
        /// </summary>
        public panMain()
        {
            InitializeComponent();
            Messenger.Default.Register<Uri>(this, "NavigationRequest", (uri) => NavigationService.Navigate(uri));
           
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            listFeatured.SelectedIndex = -1;
            lbMeetings.SelectedIndex = -1;
            listTwitter.SelectedIndex = -1;
            lbMain.SelectedIndex = -1;
        }

        private void PhoneApplicationPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            LittleWatson.CheckForPreviousException();
            
        }

        private void btnTwitterRefresh_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var vm = DataContext as panMainViewModel;
            if (vm != null)
            {
                vm.TwitterSearchCommand.Execute(null);
            }
        }

        private void btnGroupAppsRefresh_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var vm = DataContext as panMainViewModel;
            if (vm != null)
            {
                vm.GroupAppsSearchCommand.Execute(null);
            }
        }

        private void btnMeetingRefresh_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var vm = DataContext as panMainViewModel;
            if (vm != null)
            {
                vm.MeetingsSearchCommand.Execute(null);
            }
        }
    }
}